<template>
    <div class="bg">
        <div class="top">
            <div class="topw">我的收藏</div>
            <div class="topd">
            </div>
        </div>
        <!--        没有数据-->
        <div class="show">
            <span v-if="notdata" class="el-icon-film"
                  style="font-family: 隶书;font-size: 30px;color: gray">暂时没有数据</span>
        </div>
        <!--        有数据-->
        <div v-if="!notdata" class="haveData" v-for="(item,index) in MyCourseData" :key="index">
            <div class="img_div"><img style="height: 85px;width: 175px" :src="item.cover"></div>
            <div class="sp_div"><span>{{item.title}}</span></div>
            <div class="r_div">
                <div>
                    <el-button plain @click="tiaozhuan(item.id)">进入学习</el-button>
                </div>
                <div style="margin: 30px 0 20px 20px">
                    <span class="r_s_div" @click="noSC(item.id)">取消收藏</span>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "collection",
        data() {
            return {
                notdata: true,
                userData:{},
                MyCourseData:[],
            }
        },
        methods:{

            //查询用户
            searchMember() {
                var that = this;
                var token = sessionStorage.getItem("token");
                this.$http.get(`/member/findMemberByToken/${token}`).then(function (successCallback) {
                    if (successCallback.data.code === 2000) {
                        that.userData = successCallback.data.result;
                        that.findMyCourse()
                    }
                })
            },
            findMyCourse(){
                var that=this;
                this.$http.get(`/core/course/finMyCourse/${that.userData.id}`).then(function (success) {
                    if (success.data.code===200){
                        that.MyCourseData=success.data.result;
                        if (that.MyCourseData.length!==0){
                            that.notdata=false;
                        }
                    }
                })
            },
            tiaozhuan(id) {
                this.$router.push({
                    path:'/courseDetails',
                    query:{
                        key:id
                    }
                })
            },
            noSC(courseId){
                var that=this;
                this.$http.get(`/core/course/noSC/${that.userData.id}/${courseId}`).then(function (success) {
                    if (success.data.code===200){
                        that.$message.success("取消成功")
                    }else {
                        that.$message.error("取消失败")
                    }

                    that.findMyCourse();
                })
            }
        },
        created() {
            this.searchMember();
        }
    }
</script>

<style scoped>

</style>